"""
场地相关 Schemas
"""
from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime
from app.schemas.common import Location


class VenueBase(BaseModel):
    """场地基础信息"""
    name: str = Field(..., min_length=1, max_length=200)
    type: str = Field(..., pattern="^(11|7|5)$")
    latitude: float
    longitude: float
    address: str
    price: float = Field(..., gt=0)
    grassType: str = Field(..., pattern="^(natural|artificial)$")
    facilities: List[str] = []
    images: List[str] = []
    businessHours: str = "08:00-22:00"
    hasParking: bool = False
    hasShower: bool = False
    cityId: str


class VenueCreate(VenueBase):
    """创建场地"""
    managerId: str


class VenueUpdate(BaseModel):
    """更新场地"""
    name: Optional[str] = Field(None, min_length=1, max_length=200)
    price: Optional[float] = Field(None, gt=0)
    facilities: Optional[List[str]] = None
    images: Optional[List[str]] = None
    businessHours: Optional[str] = None
    status: Optional[str] = Field(None, pattern="^(available|booked|maintenance)$")


class VenueResponse(VenueBase):
    """场地响应"""
    id: str
    location: Location
    rating: float = 0.0
    reviewCount: int = 0
    status: str = "available"
    managerId: str
    
    class Config:
        from_attributes = True


class VenueFilter(BaseModel):
    """场地筛选条件"""
    cityId: Optional[str] = None
    city: Optional[str] = None  # 城市名称
    type: Optional[str] = Field(None, pattern="^(11|7|5)$")
    minPrice: Optional[float] = None
    maxPrice: Optional[float] = None
    maxDistance: Optional[float] = None
    grassType: Optional[str] = Field(None, pattern="^(natural|artificial)$")
    sortBy: Optional[str] = Field("distance", pattern="^(distance|price|rating)$")


class TimeSlotBase(BaseModel):
    """时段基础信息"""
    venueId: str
    date: str = Field(..., pattern=r"^\d{4}-\d{2}-\d{2}$")
    startTime: str = Field(..., pattern=r"^\d{2}:\d{2}$")
    endTime: str = Field(..., pattern=r"^\d{2}:\d{2}$")
    price: float = Field(..., gt=0)


class TimeSlotCreate(TimeSlotBase):
    """创建时段"""
    pass


class TimeSlotResponse(TimeSlotBase):
    """时段响应"""
    id: str
    status: str = "available"
    currentPlayers: int = 0
    maxPlayers: int = 0
    bookingId: Optional[str] = None
    
    class Config:
        from_attributes = True

